using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using GameLogic.AbilitySystem.Attribute;
using GameLogic.AbilitySystem.Effect;
using UnityEngine;



namespace GameLogic.AbilitySystem
{
    /// <summary>
    /// 这里有一些数值集之间相互作用的效果
    /// </summary>
    public static class gf
    {
        /// <summary>
        /// 类T的深拷贝拓展
        /// 该类T必须标志为Serializable可序列化
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static T DeepCopy<T>(this T obj)
            where T : class
        {
            try
            {
                if (obj == null)
                {
                    return null;
                }
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                using (MemoryStream stream = new MemoryStream())
                {
                    binaryFormatter.Serialize(stream, obj);
                    stream.Position = 0;
                    return (T)binaryFormatter.Deserialize(stream);
                }
            }
            catch
            {
                return null;
            }


        }
    }
}